<%@ tag language="java" pageEncoding="UTF-8"
	deferredSyntaxAllowedAsLiteral="false" trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ attribute name="id" required="true" type="java.lang.String"
	description="唯一标识."%>
<%@ attribute name="relationId" required="true" type="java.lang.String"
	description="relationId"%>
<%@ attribute name="typeKey" required="false" type="java.lang.String"
	description="typeKey"%>
<%@ attribute name="formId" required="true" type="java.lang.String"
	description="formId"%>
<%@ attribute name="gridId" required="true" type="java.lang.String"
	description="gridId"%>
<%@ attribute name="detailSaveUrl" required="false"
	type="java.lang.String" description="detailSaveUrl"%>


<c:set var="detailSaveUrl"
	value="${empty detailSaveUrl ?'sparepart/sparepartChangeDetail/saveDetails' :detailSaveUrl }"></c:set>

<isperp:listSelector id="${id }" showClearBtn="false" 
	displayValueCssClass="hidden" selectorCssClass="hidden" 
	url="sparepart/sparepart/listDetail?sptType=in&relationId=${relationId }"
	afterSelected="${id }_afterSelected(rows);"
	multiselect="true">
	<isperp:column name="id" title="id" hidden="true"></isperp:column>
	<isperp:column name="code" title="编号" width="120">
	</isperp:column>
	<isperp:column name="treenode_name_path" title="备件分类" width="120">
	</isperp:column>
	<isperp:column name="name" title="名称" width="160">
	</isperp:column>
	<isperp:column name="model" title="型号" width="120">
	</isperp:column>
	<isperp:column name="unit" title="单位" width="60" align="center">
	</isperp:column>
	<isperp:column name="cur_stock_quantity" title="库存" width="70"
		align="center" >
	</isperp:column>
	<isperp:column name="min_stock_result" title="最小库存" width="80"
		align="center">
	</isperp:column>

</isperp:listSelector>

<script type="text/javascript"> 
	
	function ${id }_afterSelected(rows) {
		if (rows.length < 1) {
			isperp.alert("没有数据被选择！")
			return;
		}
		isperp.submitForm({
			formId : "${formId}",
			success : function() {
				var ids = rows[0].id;
				for ( var i = 1; i < rows.length; i++) {
					var item = rows[i];
					ids = ids + "," + item.id;
				}
				//异步创建服务目录
				$.post("${detailSaveUrl}", {
					relationId : '${relationId}',
					sparepartIds : ids,
					typeKey:'${typeKey}'
				}, function(data) {
					${gridId }.reload();//刷新已选
				});
			}
		});

	}
</script>
